<template>
  <div id="app">
    <Title class="title-bar" v-if="$route.meta.isShowTitle"></Title>
    <router-view :key="$route.fullPath"></router-view>
  </div>
</template>

<script>
import Title from "@/components/Title"

export default{
  name: 'App',
  components: {
    Title
  },
  mounted() {
    this.mountTimeTrans();
  },
  beforeDestroy() {
    this.$bus.$off('timeTrans');
  },
  methods:{
    // 时间格式化：国际时间转YYYY-MM-DD hh:mm:ss
    formatDate(time){
      let date = new Date(time);
      const year = date.getFullYear();
      const month = date.getMonth();
      const day = date.getDate();
      const hour = date.getHours();
      const min = date.getMinutes();
      const sec = date.getSeconds();

      return `${year}-${month}-${day} ${hour}:${min}:${sec}`;
    },

    // 国际标准时间转北京时间time:时间戳
    timeTrans(time){
      let date = new Date(new Date(time).getTime() + 8 * 3600 * 1000);
      date = this.formatDate(time);
      return date;
    },

    // 挂载TimeTrans公共事件到全局事件总线中。
    mountTimeTrans(){
      // @desc:  时间戳转DateTime方法。
      // @Param: {Function}[fun]
      // @Param: {String}[time]
      this.$bus.$on('timeTrans', (time, fun)=>{
        if (time == 0)console.log("$on:Detail=timeTrans,$off:app.vue");
        let date = this.timeTrans(time);
        fun(date);
      })
    }
  },
}
</script>

<style lang="less">
a{
  text-decoration: none;
  color: #FFFFFF;
}
</style>
